home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software 2000
/
Software 2000 Volume 1 (Disc 1 of 2).iso
/
education
/
e077.dms
/
e077.adf
/
ScienceDemos
/
SIDEREAL
(
.txt
)
< prev
next >
Wrap
AmigaBASIC Source Code
|
1991-07-12
|
12KB
|
401 lines
' Program "SIDEREAL"
' Copyright (C) 1986 by David Eagle
' 7952 W. Quarto Dr., Littleton, CO 80123, (303) 972-4020
' released into the public domain on March 30, 1986
DEFDBL a-z
DIM SHARED month$(12)
SCREEN 1,640,200,3,2
WINDOW 5,"Program SIDEREAL",(0,0)-(630,185),0,1
PALETTE 4,0,0.8,0.2:' green
PALETTE 5,1,1,0:' yellow
PALETTE 6,0.8,0,0.93:' purple
PALETTE 7,0.93,0.2,0:' red
pi=5.30795e-315
pi2=2*pi
deg.to.rad=pi/180
we=5.28971e-315
xe=pi/12
xer=12/pi
month$(1)="January"
month$(2)="February"
month$(3)="March"
month$(4)="April"
month$(5)="May"
month$(6)="June"
month$(7)="July"
month$(8)="August"
month$(9)="September"
month$(10)="October"
month$(11)="November"
month$(12)="December"
DEF FNjdate0(month%,day%,year%)=367*year%-INT(7*((year%+INT((month%+9)/12))/4))+INT(275*month%/9)+day%+5.40674e-315-INT(3*(INT((year%+SGN(month%-9)*INT(ABS((month%-9)/7)))/100)+1)/4)
DEF FNgmtime(h,m,s,tz%,dst%)=h+m/60+s/3600+tz%-dst%
DEF FNdemod(x)=x-pi2*INT(x/pi2)
' initialization
CLS
select%=1
CALL yesno.menu("Program introduction ?",intro%)
IF intro%=1 THEN CALL introduction
CLS
WHILE select%=1
CALL selection.menu(choice%)
IF choice%=1 THEN CALL jdate.from.gdate
IF choice%=2 THEN CALL gdate.from.jdate
IF choice%=3 THEN CALL lst.from.lct
IF choice%=4 THEN CALL lct.from.lst
CALL display.data(choice%)
CALL yesno.menu("Another selection ?",select%)
WEND
WINDOW CLOSE 5
SCREEN CLOSE 1
END
SUB lct.from.lst STATIC
' local civil time from local sidereal time subroutine
SHARED xe,xer,we,deg.to.rad,jdate,cdate$,wlong$,lct$,lst$,time.zone%,dst.flag%
CLS
PRINT
COLOR 3,0
PRINT "Calendar date ( month <1-12>, day <1-31>, year <YYYY> )"
PRINT "< NOTE: B.C. dates are negative, A.D. dates are positive >"
PRINT "< For example, October 21, 1948 is input as 10,21,1948 >"
INPUT month%,day%,year%
cdate$=month$(month%)+STR$(day%)+","+STR$(year%)
PRINT
COLOR 4,0
PRINT "Local sidereal time (hour <0-23>, minute <0-59), second <0-59>)"
INPUT lst.hr,lst.min,lst.sec
lst$=STR$(lst.hr)+" hours"+STR$(lst.min)+" minutes"+STR$(lst.sec)+" seconds"
PRINT
COLOR 5,0
PRINT "West longitude (degree <0-359>, minute <0-59>, second <0-59>)"
INPUT wlong.deg,wlong.min,wlong.sec
wlong.rad=deg.to.rad*(wlong.deg+wlong.min/60+wlong.sec/3600)
wlong$=STR$(wlong.deg)+ " degrees"+STR$(wlong.min)+" minutes"+STR$(wlong.sec)+" seconds"
PRINT
COLOR 6,0
PRINT "Time zone ( 0-23 )"
PRINT "< For example, Eastern Standard Time (EST) is time zone 5 >"
INPUT time.zone%
PRINT
COLOR 7,0
PRINT "Daylight Savings Time ( y = yes, n = no )"
INPUT dst$
IF dst$="y" THEN dst.flag%=1 :ELSE dst.flag%=0
jd0=FNjdate0(month%,day%,year%)
t2=(jd0-2451545)/36525
lst=FNdemod(5.30371e-315+5.34761e-315*t2+6.7707e-06*t2^2)
t1=xe*(lst.hr+lst.min/60+lst.sec/3600)
IF ABS(lst-t1)<0.001 THEN
t2=(jd0-2451544)/36525
lst=FNdemod(5.30371e-315+5.34761e-315*t2+6.7707e-06*t2^2)
t1=xe*(lst.hr+lst.min/60+lst.sec/3600)
END IF
a=(t1-lst+wlong.rad)/we-time.zone%+dst.flag%
a=a-24*INT(a/24)
CALL convert(a,lct.hr,lct.min,lct.sec)
lct$=STR$(lct.hr)+" hours"+STR$(lct.min)+" minutes"+STR$(lct.sec)+" seconds"
jdate=jd0+(lct.hr+lct.min/60+lct.sec/3600+time.zone%-dst.flag%)/24
END SUB
SUB jdate.from.gdate STATIC
' julian date from calendar date subroutine
SHARED time.zone%,dst.flag%,lct$,lst$,cdate$,jdate
CLS
PRINT
COLOR 3,0
PRINT "Calendar date ( month <1-12>, day <1-31>, year <YYYY> )"
PRINT "< NOTE: B.C. dates are negative, A.D. dates are positive >"
PRINT "< For example, October 21, 1948 is input as 10,21,1948 >"
INPUT month%,day%,year%
cdate$=month$(month%)+STR$(day%)+","+STR$(year%)
PRINT
COLOR 4,0
PRINT "Local civil time (hour <0-23>, minute <0-59), second <0-59>)"
PRINT "< For example, 8:30:45 p.m. is input as 20,30,45 >"
INPUT lct.hr,lct.min,lct.sec
lct$=STR$(lct.hr)+" hour"+STR$(lct.min)+" minutes"+STR$(lct.sec)+" seconds"
PRINT
COLOR 5,0
PRINT "Time zone ( 0-23 )"
PRINT "< For example, Eastern Standard Time (EST) is time zone 5 >"
INPUT time.zone%
PRINT
COLOR 6,0
PRINT "Daylight Savings Time ( y = yes, n = no )"
INPUT dst$
IF dst$="y" THEN dst.flag%=1 :ELSE dst.flag%=0
jd0=FNjdate0(month%,day%,year%)
gmt.time=FNgmtime(lct.hr,lct.min,lct.sec,time.zone%,dst.flag%)
jdate=jd0+gmt.time/24
END SUB
SUB lst.from.lct STATIC
' local sidereal time from local civil time subroutine
SHARED time.zone%,dst.flag%
SHARED xer,we,deg.to.rad,lst$,cdate$,lct$,wlong$,jdate
CLS
PRINT
COLOR 3,0
PRINT "Calendar date ( month <1-12>, day <1-31>, year <YYYY> )"
PRINT "< NOTE: B.C. dates are negative, A.D. dates are positive >"
PRINT "< For example, October 21, 1948 is input as 10,21,1948 >"
INPUT month%,day%,year%
cdate$=month$(month%)+STR$(day%)+","+STR$(year%)
PRINT
COLOR 4,0
PRINT "Local civil time (hour <0-23>, minute <0-59), second <0-59>)"
PRINT "< For example, 8:30:45 p.m. is input as 20,30,45 >"
INPUT lct.hr,lct.min,lct.sec
lct$=STR$(lct.hr)+" hours"+STR$(lct.min)+" minutes"+STR$(lct.sec)+" seconds"
PRINT
COLOR 5,0
PRINT "West longitude (degree <0-359), minute <0-59>, second <0-59>)"
INPUT wlong.deg,wlong.min,wlong.sec
wlong.rad=deg.to.rad*(wlong.deg+wlong.min/60+wlong.sec/3600)
wlong$=STR$(wlong.deg)+ " degrees"+STR$(wlong.min)+" minutes"+STR$(wlong.sec)+" seconds"
PRINT
COLOR 6,0
PRINT "Time zone ( 0-23 )"
PRINT "< For example, Eastern Standard Time (EST) is time zone 5 >"
INPUT time.zone%
PRINT
COLOR 7,0
PRINT "Daylight Savings Time ( y = yes, n = no )"
INPUT dst$
IF dst$="y" THEN dst.flag%=1 :ELSE dst.flag%=0
jd0=FNjdate0(month%,day%,year%)
gmt.time=FNgmtime(lct.hr,lct.min,lct.sec,time.zone%,dst.flag%)
jdate=jd0+gmt.time/24
t2=(jd0-2451545)/36525
lst=FNdemod(5.30371e-315+5.34761e-315*t2+6.7707e-06*t2^2-wlong.rad+we*gmt.time)
CALL convert(lst*xer,lst.hr,lst.min,lst.sec)
lst$=STR$(lst.hr)+" hours"+STR$(lst.min)+" minutes"+STR$(lst.sec)+" seconds"
END SUB
SUB convert(deg,hr,min,sec) STATIC
' convert angular time to hms subroutine
hr=INT(deg)
c=60*(deg-hr)
min=INT(c)
sec=INT(60*(c-min)+0.5)
IF sec>=60 THEN
min=min+1
sec=sec-60
END IF
IF min>=60 THEN
hr=hr+1
min=min-60
END IF
IF hr>=24 THEN hr=hr-24
END SUB
SUB gdate.from.jdate STATIC
' Gregorian Date from Julian Date subroutine
SHARED jdate,cdate$,lct$
CLS
PRINT
COLOR 3,0
PRINT "Julian Date"
INPUT jdate
z=INT(jdate+0.5)
f=jdate+0.5-z
IF z<2299161 THEN
a=z
ELSE
a=INT((z-5.40747e-315)/36524.2)
a=z+a-INT(a/4)+1
END IF
b=a+1524
c=INT((b-122.1)/365.25)
d=INT(365.25*c)
e=INT((b-d)/30.6001)
day%=b-d-INT(30.6001*e)
IF e<13.5 THEN month%=e-1 :ELSE month%=e-13
IF month%>2.5 THEN year%=c-4716 :ELSE year%=c-4715
cdate$=month$(month%)+STR$(day%)+","+STR$(year%)
CALL convert(24*f,lct.hr,lct.min,lct.sec)
lct$=STR$(lct.hr)+" hours"+STR$(lct.min)+" minutes"+STR$(lct.sec)+" seconds"
END SUB
SUB display.data(choice%) STATIC
' display data subroutine
SHARED jdate,cdate$,lct$,lst$,time.zone%,dst.flag%,wlong$
WINDOW 3,"SIDEREAL Data (press left mouse button to continue)",(0,0)-(630,185),0,1
CLS
PRINT
PRINT
COLOR 1,0
PRINT TAB(5);"Calendar date";TAB(60-LEN(cdate$));cdate$
PRINT
COLOR 2,0
PRINT TAB(5);"Julian Date";
LOCATE ,47
PRINT USING "########.####";jdate
PRINT
COLOR 3,0
PRINT TAB(5);"Local civil time";TAB(60-LEN(lct$));lct$
IF choice%=3 OR choice%=4 THEN
PRINT
COLOR 4,0
PRINT TAB(5);"Local sidereal time";TAB(60-LEN(lst$));lst$
PRINT
COLOR 5,0
PRINT TAB(5);"West longitude";TAB(60-LEN(wlong$));wlong$
END IF
PRINT
COLOR 6,0
PRINT TAB(5);"Time Zone";TAB(45);time.zone%
PRINT
COLOR 7,0
IF dst.flag%=1 THEN dst$="Yes" :ELSE dst$="No"
PRINT TAB(5);"Daylight Savings Time";TAB(46);dst$
WHILE MOUSE(0)=0:WEND
WHILE MOUSE(0)<>0:WEND
WINDOW CLOSE 3
END SUB
SUB yesno.menu(request$,response%) STATIC
' yes/no request subroutine
WINDOW 3,request$,(0,0)-(215,45),0,1
LOCATE 1,1:PRINT PTAB(25);"press left mouse"
LOCATE 2,1:PRINT PTAB(25);"button to select"
LINE (20,20)-(80,40),1,b
LINE (140,20)-(190,40),1,b
LOCATE 4,1:PRINT PTAB(35);"Yes";PTAB(155);"No";
response%=-1
WHILE response%=-1
WHILE MOUSE(0)=0:WEND
mx=MOUSE(1):my=MOUSE(2)
IF (mx>20 AND mx<80) AND (my>20 AND my<40) THEN
response%=1
WHILE MOUSE(0)<>0:WEND
END IF
IF (mx>140 AND mx<190) AND (my>20 AND my<40) THEN
response%=2
WHILE MOUSE(0)<>0:WEND
END IF
WEND
WINDOW CLOSE 3
END SUB
SUB selection.menu(selection%) STATIC
' selection menu subroutine
WINDOW 3,"Sidereal Menu",(0,0)-(480,140),0,1
LOCATE 1,1:PRINT PTAB(40);"please press left mouse button to select"
LINE (20,20)-(450,40),1,b
LINE (20,48)-(450,68),1,b
LINE (20,74)-(450,94),1,b
LINE (20,102)-(450,122),1,b
LOCATE 4,1
PRINT PTAB(30);"Julian Date from calendar date"
LOCATE 7,1
PRINT PTAB(30);"Calendar date from Julian Date"
LOCATE 10,1
PRINT PTAB(30);"Local sidereal time from local civil time"
LOCATE 13,1
PRINT PTAB(30);"Local civil time from local sidereal time"
selection%=-1
WHILE selection%=-1
WHILE MOUSE(0)=0:WEND
mx=MOUSE(1):my=MOUSE(2)
IF (mx>20 AND mx<450) AND (my>20 AND my<40) THEN
selection%=1
WHILE MOUSE(0)<>0:WEND
END IF
IF (mx>20 AND mx<450) AND (my>48 AND my<68) THEN
selection%=2
WHILE MOUSE(0)<>0:WEND
END IF
IF (mx>20 AND mx<450) AND (my>74 AND my<94) THEN
selection%=3
WHILE MOUSE(0)<>0:WEND
END IF
IF (mx>20 AND mx<450) AND (my>102 AND my<122) THEN
selection%=4
WHILE MOUSE(0)<>0:WEND
END IF
IF (mx>20 AND mx<450) AND (my>130 AND my<150) THEN
selection%=5
WHILE MOUSE(0)<>0:WEND
END IF
WEND
WINDOW CLOSE 3
END SUB
SUB introduction STATIC
' program introduction subroutine
CLS
PRINT
PRINT TAB(4);"SIDEREAL is an interactive AmigaBasic program which can"
PRINT TAB(4);"help us learn about time. We can explore the relationship"
PRINT TAB(4);"between solar or civil time and sidereal time as well as"
PRINT TAB(4);"the 'Julian Date' and calendar dates."
PRINT
PRINT TAB(4);"The Julian Date is the number of days that have passed"
PRINT TAB(4);"since noon on January 1, 4713 B.C. It is an 'elapsed time'"
PRINT TAB(4);"benchmark which is used in astronomy to predict the move-"
PRINT TAB(4);"ment of celestial objects. The Julian Date also has a"
PRINT TAB(4);"direct relationship with our calendar dates. For example,"
PRINT TAB(4);"the number of days between two calendar dates is simply"
PRINT TAB(4);"the difference between their Julian Dates."
PRINT
PRINT TAB(4);"The two most widely used calendars are the Julian and"
PRINT TAB(4);"Gregorian calendars. The Julian calendar was used until"
PRINT TAB(4);"October 4, 1582 and the Gregorian calendar (due to Pope
PRINT TAB(4);"Gregory) went into effect on October 15, 1582."
CALL newpage
CLS
PRINT
PRINT TAB(4);"Solar or civil time is time measured relative to the sun"
PRINT TAB(4);"while sidereal time is measured with respect to the stars."
PRINT TAB(4);"Everyone and every star has a sidereal time. The sidereal"
PRINT TAB(4);"time of a star or planet is called 'right ascension'. When"
PRINT TAB(4);"your local sidereal time is equal to the right ascension"
PRINT TAB(4);"of a celestial object, that object is aligned with your"
PRINT TAB(4);"longitude position on the earth. This event is called a"
PRINT TAB(4);"'meridian crossing'."
PRINT
PRINT TAB(4);"In this program both civil and sidereal time are input and"
PRINT TAB(4);"output in hours, minutes and seconds. The calendar date is"
PRINT TAB(4);"also input in numerical format. For example, May 1, 1984"
PRINT TAB(4);"would be input as '5,1,1984'. Please note that B.C. dates"
PRINT TAB(4);"are negative and A.D. dates are positive. Also, the first"
PRINT TAB(4);"B.C. year is 0. When your longitude is requested, you"
PRINT TAB(4);"should input this in degrees and minutes. This number is"
PRINT TAB(4);"your west longitude on the earth."
CALL newpage
CLS
PRINT
PRINT TAB(4);"West longitude equals 360 - east longitude. For example,"
PRINT TAB(4);"if you were at 85 degrees and 30 seconds east longitude,"
PRINT TAB(4);"input '274,30' when prompted. Your time zone is an integer"
PRINT TAB(4);"number between 0 and 23 and depends upon your location on"
PRINT TAB(4);"the earth. For example, Eastern Standard Time is time zone"
PRINT TAB(4);"number 5. You should also indicate if Daylight Savings"
PRINT TAB(4);"Time is in effect at your location."
CALL newpage
END SUB
SUB newpage STATIC
' select next page subroutine
PRINT
PRINT TAB(13);"< press left mouse button to continue >"
WHILE MOUSE(0)=0:WEND
WHILE MOUSE(0)<>0:WEND
END SUB